/*
 * @Description: 项目配置
 * @Author: lijinpeng
 * @Date: 2020-07-26 22:35:10
 * @LastEditors: lijinpeng
 */ 
// gzip压缩
const CompressionWebpackPlugin = require('compression-webpack-plugin')
// 是否使用gzip
const productionGzip = true
// 需要gzip压缩的文件后缀
const productionGzipExtensions = ['js', 'css']

module.exports = {
  publicPath: process.env.BASE_URL,
  devServer: {
    port: 8010,
    disableHostCheck: true,
    proxy: {
      '/api': {
        target: 'https://XXX.XXXX.com',
        changeOrigin: true
      }
    }
  },
  // transpileDependencies: [/\/node_modules\/vue-echarts\//],
  configureWebpack: () => {
    const myConfig = {}
    myConfig.plugins = []
    if (process.env.NODE_ENV === 'production') {
      // 2. 构建时开启gzip，降低服务器压缩对CPU资源的占用，服务器也要相应开启gzip
      productionGzip &&
        myConfig.plugins.push(
          new CompressionWebpackPlugin({
            test: new RegExp('\\.(' + productionGzipExtensions.join('|') + ')$'),
            threshold: 8192,
            minRatio: 0.8
          })
        )
    }
    if (process.env.NODE_ENV === 'development') {
      /**
       * 关闭host check，方便使用ngrok之类的内网转发工具
       */
      myConfig.devServer = {
        disableHostCheck: true
      }
    }

    return myConfig
  },
  productionSourceMap: false
}